package com.esri.core.symbol;

import com.esri.core.internal.util.d;
import com.esri.core.internal.util.h;
import java.io.StringWriter;
import java.util.LinkedList;
import java.util.List;
import org.codehaus.jackson.JsonGenerator;
import org.codehaus.jackson.JsonNode;
import org.codehaus.jackson.node.ArrayNode;

/* loaded from: classes.dex */
public class CompositeSymbol implements Symbol {
    private static final long serialVersionUID = 1;
    private List<Symbol> a;

    public CompositeSymbol() {
        this.a = new LinkedList();
    }

    public CompositeSymbol(List<Symbol> list) {
        setSymbols(list);
    }

    public CompositeSymbol(JsonNode jsonNode) {
        if (jsonNode == null) {
            throw new NullPointerException("Input symbol cannot be null.");
        }
        this.a = new LinkedList();
        ArrayNode arrayNode = (ArrayNode) jsonNode.get("symbols");
        for (int i = 0; i < arrayNode.size(); i++) {
            try {
                this.a.add(h.a(d.c(arrayNode.get(i).toString())));
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    }

    public void add(Symbol symbol) {
        if (symbol == null) {
            throw new NullPointerException("Input symbol cannot be null.");
        }
        if (equals(symbol)) {
            throw new RuntimeException("Cannot add composite symbol to itself.");
        }
        try {
            this.a.add(symbol.copy());
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    public void removeAll() {
        this.a.clear();
    }

    public List<Symbol> getSymbols() {
        return new LinkedList(this.a);
    }

    public void setSymbols(List<Symbol> list) {
        if (list == null) {
            throw new NullPointerException("Input symbols cannot be null.");
        }
        this.a = new LinkedList();
        for (Symbol symbol : list) {
            if (symbol == null) {
                throw new NullPointerException("Input symbol cannot be null.");
            }
            add(symbol);
        }
    }

    @Override // com.esri.core.symbol.Symbol
    public String toJson() throws Exception {
        StringWriter stringWriter = new StringWriter();
        JsonGenerator a = d.a(stringWriter);
        a.writeStartObject();
        a.writeStringField("type", "esriCS");
        a.writeArrayFieldStart("symbols");
        for (Symbol symbol : this.a) {
            a.writeRawValue(symbol.toJson());
        }
        a.writeEndArray();
        a.writeEndObject();
        a.close();
        return stringWriter.toString();
    }

    @Override // com.esri.core.symbol.Symbol
    public Symbol copy() throws Exception {
        return new CompositeSymbol(this.a);
    }
}
